< previous page page_297 next page >

Page 297
z0317-01.gif
Figure 10.17
Depth one, two, and three Hilbert curves.
Hilbert Curves
Figure 10.17 shows Hilbert curves of level one, two, and three. To create a Hilbert curve of a given level, you draw four Hilbert curves of one less level and connect them with line segments. The picture on the left in Figure 10.18 shows how four level-one curves make up a level-two curve. The picture on the right shows how four level-two curves make up a level-three curve. The smaller curves in each picture are shown in bold lines so that you can see them easily.
Because the smaller curves that make up a Hilbert curve are rotated, the drawing routine must be able to draw curves with different orientations. The easiest way to accomplish this is to pass the routine two parameters, dx and dy, that indicate the direction in which the first line in the curve should be drawn. Then if the curve is a level-one curve, the first drawing command is Line -Step(dx, dy), assuming the drawing position is already at the correct location.
If the curve is not a level-one curve, the drawing routine begins by recursively calling itself to draw a smaller curve with the parameters dx and dy switched. This gives the smaller curve the proper orientation.
For example, consider the curve on the left in Figure 10.18. This level-two curve begins with parameters dx = S and dy = 0 where S is the length of one of the curve's segments. The drawing routine begins by calling itself recursively with dx = 0 and dy = S to draw a level-one curve. Because the new curve has level one, the drawing routine draws the level-one curve beginning with the statement Line -Step(dx, dy), which, in this case, is equivalent to Line -Step(0, S). Keeping in mind that the positive Y direction is down, you can see that this agrees with the first segment in the curve in Figure 10.18.
The Hilbert curve-drawing routine is surprisingly concise in Visual Basic, but it is a little hard to understand. You may need to step through the code several times in the debugger to understand how dx and dy switch to produce the different pieces of the curves.
z0317-02.gif
Figure 10.18
Hilbert curves made up of smaller Hilbert curves.

 
< previous page page_297 next page >